package de.ubschmidt.capi;

import java.nio.ByteBuffer;

/**
 * This message confirms the acceptance of the LISTEN_REQ.
 * Any errors are coded in the parameter Info.
 */
public class ListenConf
        extends CapiPassiveMessage
        implements ControllerAccessor, InfoAccessor {

    /**
     * @param byteBuffer
     */
    public ListenConf(final ByteBuffer byteBuffer) {
        super(byteBuffer);
    }

    /** {@inheritDoc} */
    public int getController() {
        return getByteBuffer().getInt(OFFSET_MESSAGE);
    }

    /** {@inheritDoc} */
    public ErrorInfo getInfo() {
        return ErrorInfo.valueOf(getByteBuffer().getShort(OFFSET_MESSAGE + 4));
    }

    /** {@inheritDoc} */
    @Override
    public String toString() {
        String s = String.format("%s[%s ctrl=%d info=%s]",
                getClass().getSimpleName(),
                super.toString(),
                getController(),
                getInfo());

        return s;
    }

}
